package com.lingxu.module.collection.controller;

import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.system.manage.vo.LoginUser;
import com.lingxu.module.collection.entity.*;
import com.lingxu.module.collection.service.IHomePageService;
import com.lingxu.module.homeIndex.entity.ParamsDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags="首页")
@RestController
@RequestMapping("/homePage")
public class HomePageController {

    @Resource
    private IHomePageService homePageService;

    @ApiOperation(value="首页-获取模型使用情况", notes="信息发布-获取模型使用情况")
    @PostMapping(value = "/getModelUseInfo")
    public Result<?> getModelUseInfo() {
        LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String region= user.getRegion();
        if(StringUtils.isBlank(region)){
            region="320000";
        }
        List<ModelUseInfo> list=homePageService.getModelUseInfo(region);
        return Result.ok(list);
    }

    @ApiOperation(value="首页-获取用户使用情况", notes="信息发布-获取用户使用情况")
    @PostMapping(value = "/getUseCount")
    public Result<?> getUseCount(@RequestBody ParamsDTO dto) {
        if(StringUtils.isBlank(dto.getAreaCode())){
            dto.setAreaCode("320800");
        }
        List<UserCountInfo> list=homePageService.getUseCount(dto);
        return Result.ok(list);
    }

    @ApiOperation(value="首页-获取地区模型使用情况", notes="信息发布-获取地区模型使用情况")
    @PostMapping(value = "/getAreaModelCount")
    public Result<?> getAreaModelCount() {
        LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String region= user.getRegion();
        if(StringUtils.isBlank(region)){
            region="320000";
        }
        List<UserCountInfo> list=homePageService.getAreaModelCount(region);
        return Result.ok(list);
    }

    @ApiOperation(value="首页-获取Ip使用情况", notes="信息发布-获取Ip使用情况")
    @PostMapping(value = "/getIpCount")
    public Result<?> getIpCount() {
        LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String region= user.getRegion();
        if(StringUtils.isBlank(region)){
            region="320000";
        }
        List<IpCount> list=homePageService.getIpCount(region);
        return Result.ok(list);
    }
    @ApiOperation(value="首页-获取用户登录情况", notes="信息发布-获取用户登录情况")
    @PostMapping(value = "/getUserLoginInfo")
    public Result<?> getUserLoginInfo(@RequestBody ParamsDTO dto) {
//        String region = userLoginInfo.getRegion();
        List<UserLoginInfo> list=homePageService.getUserLoginInfo(dto);
        return Result.ok(list);
    }

    @ApiOperation(value="首页-获取MODEL使用情况", notes="信息发布-获取MODEL使用情况")
    @PostMapping(value = "/getModelCount")
    public Result<?> getModelCount() {
        LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String region= user.getRegion();
        if(StringUtils.isBlank(region)){
            region="320000";
        }
        List<ModelCount> list=homePageService.getModelCount(region);
        return Result.ok(list);
    }

    @ApiOperation(value="首页-获取数据情况", notes="信息发布-获取数据情况")
    @PostMapping(value = "/getDataCount")
    public Result<?> getDataCount() {
        LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String region= user.getRegion();
        if(StringUtils.isBlank(region)){
            region="320000";
        }
        DataCount list=homePageService.getDataCount(region);
        return Result.ok(list);
    }
}
